from docx import Document
import os
parentpath = "/home/s/Download/jyzj"
sonpath = [
    "/基础/",
    "/免疫/",
    "/血液/",
    "/微生物/",
    "/质量/",
    "/生化/"
]
names = [
    "一、A1","二、A1","一、A2","二、A2",
    "A3/A4",
    "三、B","四、B","二、B"
]
def work(infile,outfile):
    doc = Document(infile)
    
    docx = doc.paragraphs
    for i,p in enumerate(docx):
        for x in names:
            if p.text == x:
                doc.paragraphs[i].clean()
    doc.save(outfile)

for k in sonpath:
    
    f = parentpath + k +"习题/2/"
    o = parentpath + k +"习题/4/"
    # os.mkdir(o)
    m = [i[2] for i in os.walk(f)]
    for x in m[0]:
        infilename = f+x
        outfilename = o + x.strip(".docx")+".docx"
        # print(outfilename)
        work(infilename,outfilename)